In [197]:
import pandas as pd
df = pd.read_csv('vehicle_positions.txt')
In [113]:
stops = pd.read_csv('Bus_Stops.csv')
In [139]:
stops.dropna(subset= ['stop_lat', 'stop_lon', 'Routes'], inplace = True)
In [214]:
df.dropna(inplace=True)
In [217]:
df.start_date = df.start_date.astype(int)
In [218]:
df.loc[df['route_id'].isin(['34', '66', '40'])]
Out[218]:
feed_time trip_id vehicle.id start_time start_date route_id direction_id schedule_relationship latitude longitude bearing stop_id current_stop_sequence current_status timestamp
12 1.578631e+09 42844620 y1921 23:20:00 20200109 66 0 0 42.355228 -71.133087 0.0 1112 25 2 1578630948
28 1.578631e+09 42843616 y1834 23:00:00 20200109 66 1 0 42.329590 -71.086380 135.0 11259 35 2 1578630949
42 1.578631e+09 42843540 y1898 23:05:00 20200109 66 0 0 42.374928 -71.118599 0.0 2168 33 2 1578630954
155 1.578631e+09 42844560 y1830 23:30:00 20200109 66 1 0 42.363678 -71.129158 0.0 2553 5 2 1578630960
225 1.578631e+09 42843598 y1875 23:15:00 20200109 66 1 0 42.333935 -71.105171 0.0 1317 27 2 1578630956
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
12010948 1.579309e+09 42843869 y1908 19:07:00 20200117 66 0 0 42.367096 -71.124931 35.0 2564 31 2 1579308532
12010973 1.579309e+09 42843786 y1811 19:29:00 20200117 66 1 0 42.353069 -71.132950 93.0 10928 14 2 1579308533
12011015 1.579309e+09 42989065 y1640 19:48:00 20200117 34 1 0 42.257122 -71.169174 182.0 10835 2 2 1579308534
12011027 1.579309e+09 42843785 y1787 19:17:00 20200117 66 1 0 42.333561 -71.118820 135.0 1313 23 2 1579308498
12011071 1.579309e+09 42987791 y1686 19:35:00 20200117 34 0 0 42.278450 -71.136894 0.0 606 13 2 1579308523

267808 rows × 15 columns

In [166]:
stops34 = stops[stops['Routes'].str.contains('34')]
In [228]:
fig = px.scatter_mapbox(
    df.loc[df['route_id'].isin(['34'])],
    lat="latitude",
    lon="longitude",
    color="vehicle.id",
    hover_data=["direction_id", "vehicle.id"],  
    color_continuous_scale=px.colors.cyclical.IceFire,
    size_max=15,
    zoom=10,
    animation_frame="start_date",
    title='Bus #34',
)
fig.show()
In [230]:
fig = px.scatter_mapbox(
    df.loc[df['route_id'].isin(['66'])],
    lat="latitude",
    lon="longitude",
    color="vehicle.id",
    hover_data=["direction_id", "vehicle.id"],  
    color_continuous_scale=px.colors.cyclical.IceFire,
    size_max=15,
    zoom=10,
    animation_frame="start_date",
    title='Bus #66',
)
fig.show()
In [229]:
fig = px.scatter_mapbox(
    df.loc[df['route_id'].isin(['59'])],
    lat="latitude",
    lon="longitude",
    color="vehicle.id",
    hover_data=["direction_id", "vehicle.id", 'route_id', 'schedule_relationship', 'current_status'],  
    color_continuous_scale=px.colors.cyclical.IceFire,
    size_max=15,
    zoom=10,
    animation_frame="start_date",
    title='Bus #59',
)
fig.show()
In [ ]:
 
In [219]:
import plotly.express as px

px.set_mapbox_access_token(open(".mapbox_token").read())
fig = px.scatter_mapbox(
    df.loc[df['route_id'].isin(['34', '66'])],
    lat="latitude",
    lon="longitude",
    color="route_id",
    hover_data=["direction_id", "vehicle.id"],  # size="car_hours",
    color_continuous_scale=px.colors.cyclical.IceFire,
    size_max=15,
    zoom=10,
    animation_frame="start_date"
)
#fig.add_scattermapbox(
#    below="''",
    #marker={"symbol": ["circle"], 'size' = 15},
#    lat=stops34.stop_lat,
#    lon=stops34.stop_lon,
#)
fig.show()
In [206]:
import numpy as np
import datetime
import time
from datetime import date

#pd.to_datetime(df66.index)
datetime.datetime.fromtimestamp(df66.feed_time[752])
#datetime.datetime.fromtimestamp(datetime.datetime.now().timestamp())
Out[206]:
datetime.datetime(2020, 1, 9, 23, 36, 44, 982151)